package com.summer.shopping.controller;

import com.summer.shopping.domain.table.HelpCenter;
import com.summer.shopping.domain.table.dto.AnswerDTO;
import com.summer.shopping.domain.table.dto.HelpCenterDTO;
import com.summer.shopping.domain.table.dto.HelpCenterQueryParam;
import com.summer.shopping.domain.table.dto.PageDTO;
import com.summer.shopping.domain.table.vo.HelpCenterVO;
import com.summer.shopping.service.HelpCenterService;
import com.summer.shopping.utils.PageResult;
import com.summer.shopping.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:
 * Package:
 * Description:
 *
 * @Author: 陈三岁
 * @Create
 * @Version
 */
@RestController
@Slf4j
@RequestMapping("help")
public class HelpCenterController {
    @Autowired
    private HelpCenterService helpCenterService;


    /**
     * 帮助中心分页查询操作
     * @param pageDTO
     * @return
     */
    @GetMapping("page")
    public Result page(PageDTO pageDTO, HelpCenterQueryParam param) {
//        log.info("》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");

        PageResult<HelpCenterVO> helpCenterVOPageResult =helpCenterService.pageQuery(pageDTO,param);

        return Result.ok(helpCenterVOPageResult);

    }

    /**
     * 提出问题，回答问题都调用这个接口
     * @param helpCenterDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody HelpCenterDTO helpCenterDTO){
        log.info("新增问题：{}",helpCenterDTO);

        helpCenterService.saveHelpCenter(helpCenterDTO);

        return Result.ok("新增成功");
    }


    @PutMapping("/answer")
    public Result answer(@RequestBody AnswerDTO answerDTO){
        log.info("回答问题：{}",answerDTO);
        helpCenterService.answerHelpCenter(answerDTO);
        return Result.ok("回答问题");

    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id){

        helpCenterService.deleteById(id);

        return Result.ok("成功删除");

    }

    @GetMapping("/{id}")
    public Result<HelpCenter> getById(@PathVariable Long id){

        HelpCenter helpCenter = helpCenterService.getById(id);

        return Result.ok(helpCenter);
    }
}
